package fillCups;

import java.awt.geom.Area;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.PriorityQueue;

public class Solution {
    public int fillCups(int[] amount) {
        // 贪心 每次都尽量的装两杯
        // 每次都抵消最多的两个
        int ans = 0;
        PriorityQueue<Integer> queue = new PriorityQueue<>((o1,o2)->o2-o1);
        for (int i = 0; i < amount.length; i++) {
            queue.add(amount[i]);
        }
        while (queue.peek()>0) {
            int a = queue.poll();
            int b = queue.peek();
            if( b>0 ) {
                b--;
            }
            a--;
            ans++;
            queue.add(a);
            queue.add(b);
        }
        return ans;
    }
}
